package com.neoyr.meeting.interceptor;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;

@Slf4j
@Component
public class CheckLoginInterceptor extends InterceptorRegistry implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
//        Object employee = request.getSession().getAttribute("employee");
//        String jsonString = JSON.toJSONString(employee);
//
//        if (jsonString == null || jsonString.equals("null")){
//
//            String error = JSON.toJSONString(Result.failed("NOT LOGIN"));
//            response.getWriter().write(error);
//            return  false;
//        };

        return true;
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        String reqUrl = request.getRequestURI();

        HandlerInterceptor.super.postHandle(request, response, handler, modelAndView);
    }
}
